package table.creators;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import controllers.AuthorHelper;
import models.Safety_check;
import models.Vehicle;
import models.Driver;
import models.Staff;
import controllers.Helper;
import controllers.TableModel;
import controllers.TableModel.AoColum;

public class Safety_checkTable {

    public static TableModel create(String current_user) {
        final String CHECK_TYPE = "|隐患排查|安全设备检查|安检";
        final String CHECK_ITEM = "|车辆行驶、方向、制动、电器、火灾|安全和宝洁设施检查|综合全面安全检查|证照标贴检查|车容车貌及轮胎检查|当前安全事故突出要点检查";
        final String CHECK_CONCLUSION = "|合格|整改";
        final String ACTION = "|修竣|待修";
    
        final String title = "车辆安检";
        String today = Helper.dateToString(new Date());
        String now = Helper.datetimeToString(new Date());

        List<AoColum> colums = new ArrayList<AoColum>();
        TableModel model = new TableModel();

        //                           name,             title,         required,     defaut,        cansearch, editable,    edit_type,    edit_data,            editable_settings    
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("id",    "编号",    false,    "",    false,    false,    "edit",    null,    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("notice_date",    "通知日期",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "date",    null,    null,  "TWOBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("vehicle.plate_number",    "车号",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Vehicle.getPlate_numberJson(),    null,  "ONEBOX",  "vehicle",  "plate_number",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("notice_who.name",    "通知司机",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Driver.getNameJson(),    null,  "ONEBOX",  "driver",  "name",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("checker.name",    "检查监督人",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Staff.getNameJson(),    null,  "ONEBOX",  "staff",  "name",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("check_site",    "检查地点",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "edit",    null,    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("check_date",    "检查日期",    true,    today,    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "date",    null,    null,  "TWOBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("check_type",    "检查类型",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Helper.getSelectOptionJson(CHECK_TYPE),    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("check_item",    "检查项目",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Helper.getSelectOptionJson(CHECK_ITEM),    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("check_conclusion",    "检查结论",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Helper.getSelectOptionJson(CHECK_CONCLUSION),    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("action",    "处理措施",    true,    "",    true,    AuthorHelper.isInRoleGroup(current_user, "0"),    "select",    Helper.getSelectOptionJson(ACTION),    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        if(AuthorHelper.isInRoleGroup(current_user, "0")) {
           colums.add(model.new AoColum("writer",    "登记人",    true,    current_user,    true,    false,    "edit",    null,    null,  "ONEBOX",  "",  "",  "",   "",   "",   "",  false));
        }
        model.buildModel(Safety_check.class, 600, title, AuthorHelper.canDo(current_user, title, "增加"), AuthorHelper.canDo(current_user, title, "搜索"), AuthorHelper.canDo(current_user, title, "删除"), colums);
        return model;
    }
}

